import { setTimeout } from "core-js"

// 用户模块
export default {
    namespaced: true,
    state() {
        return {
            // 用户信息
            profile: {
                id: '',
                account: '',
                avatar: '',
                nickname: '',
                account: '',
                mobile: '',
                token: ''
            },
            redirceUrl: '/',
            // 倒计时
            times: 0
        }
    },
    mutations: {
        // 修改用户信息，payload就是用户信息对象
        setUser(state, payload) {
            state.profile = payload
        },
        // 修改redirceUrl
        setRedirectUrl(state, url) {
            state.redirceUrl = url
        },
        // 倒计时缓存
        setTime(state) {
            // console.log(state.times)
            state.times = state.times - 1
        }
    },
    actions: {
        getTime({ commit }) {
            console.log('g')
            const timer = setInterval(() => {
                commit('setTime')
            }, 1000)
            setTimeout(() => {
                clearInterval(timer)
                console.log('销毁')
            }, 60000)
        }
    }
}